JAR files embedding

Embedding JAR files bloats the final executable significantly. The JAR files also need to be extracted when the executable is first run, which introduces an execution delay. As such, JAR files embedding is only recommended for smallish applications where the total size of the embedded JAR files is small.

Let's take a look at what happens when an executable with embedded JAR files is run. The executable will first check to see if the embedded JAR files have already been extracted. The target directory is <TEMP>\<APPCODE>. TEMP is typically c:\Documents and Settings\UserName\Local Settings\Temp. APPCODE is a unique hash value which is created from the product serial number and the application main class name. Hence, the target directory is guaranteed to be unique to applications with different main class names.

If a particular JAR file cannot be found, or if their file size or timestamp do not match, the embedded version will be extracted. Depending on the size of the JAR files, this could take considerable time and introduces a delay in the execution. Once the JAR files are extracted, the classpath is modified to point to these JAR files. Then the application starts.

When the executable is subsequently run, the extraction process does not take place. After a quick check to ensure that the JAR files are available and identical to the embedded ones, the application starts.